<template>
	<view>
		<view>
			<u-cell-group>
				<view v-for="(item,index) in dataList" :key="index">
					<u-cell-item :title="item.recordTime" :arrow="true" :arrow-direction="item.iconDirection" @click="openDateRecord(item)"></u-cell-item>
					<guessYourLike :dataList="item.houseDataList" v-show="(item.iconDirection === 'down') ? true : false"></guessYourLike>
				</view>
			</u-cell-group>
		</view>

		<u-divider>没有更多了</u-divider>
	</view>
</template>

<script>
	import guessYourLike from '../components/palte/guessYourLike.vue'
	export default {
		data() {
			return {
				dataList: [],
			};
		},
		// onLoad() {
		// 	this.getBrowseRecordData()
		// },
		onShow() {
			this.getBrowseRecordData()
		},
		methods: {
			//获取用户的浏览记录
			async getBrowseRecordData() {
				// console.log(getApp().globalData.userId)
				let browseRecordData = await this.$request({
					url: '/v1/browsing-history/list?userId=' + getApp().globalData.userId
				})
				console.log("browseRecordData", browseRecordData.data)

				let keys = []
				for (let key in browseRecordData.data) {
					keys.push(key)
				}

				// console.log("keys",keys)
				// console.log("browseRecordData.data[keys[i]]",browseRecordData.data[keys[0]])
				keys.sort().reverse()
				let dayInfo = {}
				var dataClist = []
				for (let i = 0; i < keys.length; i++) {
					let list = []
					for (let j = 0; j < browseRecordData.data[keys[i]].length; j++) {
					
						const houseDto = browseRecordData.data[keys[i]][j].houseDto
						// console.log(keys[i], houseDto)
						list.push(houseDto)
					}
					// console.log(list)
					
					
					let houseData = {
						recordTime: keys[i],
						houseDataList: {
							"recommandId": 5,
							"plateName": "最新发布",
							"isShowPlateName": false,
							"houseInfo": {
								list: list
							}
						}
					}
					dataClist.push(houseData)
					
				}
				this.dataList = dataClist
				// console.log("this.dataList", this.dataList)
				for (let i = 0; i < this.dataList.length; i++) {
					if (i === 0) {
						this.$set(this.dataList[i], "iconDirection", 'down')
					} else {
						this.$set(this.dataList[i], "iconDirection", 'right')
					}
				}
			},
			openDateRecord(item) {
				if (item.iconDirection === 'down') {
					this.$set(item, "iconDirection", 'right')
				} else {
					this.$set(item, "iconDirection", 'down')
				}
				// console.log("点击了")
				// for (let i = 0; i < this.dataList.length; i++) {
				// 	if (this.dataList[i].recordTime === item.recordTime) {
				// 		if (this.dataList[i].iconDirection === 'down') {
				// 			this.$set(this.dataList[i], "iconDirection", 'right')
				// 		} else {
				// 			this.$set(this.dataList[i], "iconDirection", 'down')
				// 		}
				// 	}
				// }
			},
			gotoDetail() {
				wx.navigateTo({
					url: './buyDetail',
					fail: function() {
						console.log("跳转失败")
					},
					success() {
						// console.log("成功跳转")
					}
				})
			}
		},
		components: {
			guessYourLike
		}
	}
</script>

<style>
	.hours-lists {
		margin-left: 10rpx;
		margin-top: 10rpx;
		height: 170rpx;
		width: 100%;
		z-index: 100;
	}

	.img-list-box {
		height: 160rpx;
		z-index: 10;
	}

	.img-list {
		height: 160rpx;
		width: 240rpx;
	}
</style>
